# Infrastructure层 - 基础设施层
cmake_minimum_required(VERSION 3.16)

# 启用 Qt 自动 MOC 处理
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 收集源文件
file(GLOB_RECURSE INFRASTRUCTURE_SOURCES "*.cpp")
file(GLOB_RECURSE INFRASTRUCTURE_HEADERS "*.h")

# 显式生成 tasking 模块 Q_OBJECT 类的 moc，避免漏掉元对象
set(TASKING_MOC_HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/tasking/task_handle.h
    ${CMAKE_CURRENT_SOURCE_DIR}/tasking/task_manager.h
    ${CMAKE_CURRENT_SOURCE_DIR}/tasking/db_worker_thread.h
)
qt6_wrap_cpp(TASKING_MOC_SOURCES ${TASKING_MOC_HEADERS})

# 创建infrastructure库
add_library(infrastructure STATIC
    ${INFRASTRUCTURE_SOURCES}
    ${INFRASTRUCTURE_HEADERS}
    ${TASKING_MOC_SOURCES}
)

# infrastructure层依赖kernel层（不依赖application避免循环依赖）
target_link_libraries(infrastructure PUBLIC
    kernel
    Qt6::Core
    Qt6::Gui     # Required for QColor in map service
    Qt6::Network
    Qt6::Sql
)
# 添加spdlog依赖 (如果找到)
if(SPDLOG_FOUND)
    if(WIN32)
        target_link_libraries(infrastructure PUBLIC ${SPDLOG_LIBRARIES})
    elseif(UNIX AND NOT APPLE)
        target_link_libraries(infrastructure PUBLIC ${SPDLOG_LIBRARIES} -pthread)
    endif()
    target_include_directories(infrastructure PUBLIC ${SPDLOG_INCLUDE_DIR})
    target_compile_definitions(infrastructure PUBLIC USE_SPDLOG)
endif()
# 包含目录
target_include_directories(infrastructure PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/src
)
